Form with Dynamic Dropdown Field

工作流概述

这是一个包含16个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "RKbQHfblpcvMGZ4w",
  "meta": {
    "instanceId": "d47f3738b860eed937a1b18d7345fa2c65cf4b4957554e29477cb064a7039870"
  },
  "name": "Form with Dynamic Dropdown Field",
  "tags": [],
  "nodes": [
    {
      "id": "aa627a35-9bea-4c07-b7e7-26f048564443",
      "name": "n8n | get wf",
      "type": "n8n-nodes-base.n8n",
      "position": [
        540,
        -180
      ],
      "parameters": {
        "operation": "get",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "requestOptions": {}
      },
      "credentials": {
        "n8nApi": {
          "id": "us0k8UE7R2MZPFBK",
          "name": "n8n account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "902a8e45-f4b4-469c-96a6-80002de5f6dc",
      "name": "n8n | update",
      "type": "n8n-nodes-base.n8n",
      "position": [
        1060,
        -180
      ],
      "parameters": {
        "operation": "update",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "requestOptions": {},
        "workflowObject": "={{ JSON.stringify($json) }}"
      },
      "credentials": {
        "n8nApi": {
          "id": "us0k8UE7R2MZPFBK",
          "name": "n8n account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3e9e5c16-0080-4cba-8a8a-8f24f7266fcb",
      "name": "On form submission",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        40,
        -620
      ],
      "webhookId": "3e975d29-df26-49fb-8dcf-abe8fe8bc4e6",
      "parameters": {
        "options": {},
        "formTitle": "Example Title",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Example text field"
            },
            {
              "fieldType": "dropdown",
              "fieldLabel": "Example dropdown",
              "fieldOptions": {
                "values": [
                  {
                    "option": "test publieke ruimtes"
                  },
                  {
                    "option": "Demonstraties"
                  },
                  {
                    "option": "Demonstraties"
                  },
                  {
                    "option": "Juridisch medewerker IE-recht  Streetlife"
                  },
                  {
                    "option": "Bamboe"
                  },
                  {
                    "option": "Klaar?"
                  },
                  {
                    "option": "Dannu?"
                  }
                ]
              }
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "0b874994-c123-44f8-b0f5-0b365b57d945",
      "name": "Google Sheets Trigger",
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "position": [
        -460,
        -180
      ],
      "parameters": {
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1F73a7uuzLAq916w2JFndumv0JhnCAvOTN-Cn_OOP3uA/edit#gid=0",
          "cachedResultName": "Blad1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1F73a7uuzLAq916w2JFndumv0JhnCAvOTN-Cn_OOP3uA",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1F73a7uuzLAq916w2JFndumv0JhnCAvOTN-Cn_OOP3uA/edit?usp=drivesdk",
          "cachedResultName": "obsidian-n8n"
        },
        "includeInOutput": "both"
      },
      "credentials": {
        "googleSheetsTriggerOAuth2Api": {
          "id": "FV58wiwivBMosfix",
          "name": "Google Sheets Trigger account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4c9bfed8-a758-40b9-9c74-53bedc1d1aa3",
      "name": "Execute Workflow",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        240,
        -620
      ],
      "parameters": {
        "options": {},
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "6e9d4a5a-9583-4b61-aea1-dd4892230e7c",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -520,
        -660
      ],
      "parameters": {
        "width": 960,
        "height": 240,
        "content": "## Form setup

- Customize your form fields. 
- The dropdown field will auto-update with values from your data source. 
- Other form fields can be added as needed (limited to one dropdown field).
- Connect to your workflow that processes the submitted form data.

### Form requires production mode for testing"
      },
      "typeVersion": 1
    },
    {
      "id": "41c364f4-5b1f-42fd-841b-a6f99b585804",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -520,
        -400
      ],
      "parameters": {
        "width": 440,
        "height": 400,
        "content": "## Data source setup

- Connect to your Google Sheet containing dropdown values
- Node can be replaced with any other data source (API, database)
- Set timing trigger"
      },
      "typeVersion": 1
    },
    {
      "id": "cda8f803-1773-4df7-90b9-4d8cd0469cd8",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -60,
        -400
      ],
      "parameters": {
        "width": 260,
        "height": 400,
        "content": "## Data formatting

- Extracts needed data from source
- Renames field to 'value' (do not change this name)"
      },
      "typeVersion": 1
    },
    {
      "id": "e9594ad1-3bb8-4da6-95b3-cb610a17c1bb",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        220,
        -400
      ],
      "parameters": {
        "height": 400,
        "content": "## Nested properties

- Transforms the data to the desired format"
      },
      "typeVersion": 1
    },
    {
      "id": "806a2502-5c6c-435c-a20e-8ca0eee92822",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        480,
        -400
      ],
      "parameters": {
        "height": 400,
        "content": "## Get Workflow 

- Gets the current workflow data"
      },
      "typeVersion": 1
    },
    {
      "id": "385c3e64-9893-4e3f-b789-abbf079fa8b1",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        740,
        -400
      ],
      "parameters": {
        "height": 400,
        "content": "## Add Dropdown Values 
- Replaces the nested parameters of the Dropdown Form Field with the nested properties sourced from the data."
      },
      "typeVersion": 1
    },
    {
      "id": "f43324fc-6790-445b-a72b-ae4afb051101",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1000,
        -400
      ],
      "parameters": {
        "height": 400,
        "content": "## Update Form 

- Replaces the current workflow’s JSON with the updated JSON containing the new Dropdown values."
      },
      "typeVersion": 1
    },
    {
      "id": "317694bd-590f-4eb4-a53f-f4d5d2d1ab16",
      "name": "Write JSON",
      "type": "n8n-nodes-base.code",
      "position": [
        280,
        -180
      ],
      "parameters": {
        "jsCode": "const inputArray = items.map(item => item.json);

const output = [
  {
    nodes: [
      {
        parameters: {
          formFields: {
            values: [
              {
                fieldOptions: {
                  values: inputArray.map(entry => ({ option: entry.value }))
                }
              }
            ]
          }
        }
      }
    ]
  }
];

// Return the transformed output
return output.map(item => ({ json: item }));"
      },
      "typeVersion": 2
    },
    {
      "id": "08b3c0b3-3df3-40d9-80ce-bd7c763fdbdb",
      "name": "Replace values",
      "type": "n8n-nodes-base.set",
      "position": [
        820,
        -180
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "38ef2b43-b903-4e96-b098-9da2d8c1c153",
              "name": "={{ 
   (() => {
      const nodeIndex = $json.nodes.findIndex(
         node => node.parameters?.formFields?.values.some(
            value => value.fieldType === 'dropdown' && value.fieldOptions?.values
         )
      );

      if (nodeIndex === -1) return 'No matching node found';

      const valueIndex = $json.nodes[nodeIndex].parameters.formFields.values.findIndex(
         value => value.fieldType === 'dropdown' && value.fieldOptions?.values
      );

      if (valueIndex === -1) return `nodes[${nodeIndex}].parameters.formFields.values - No matching dropdown value found`;

      return `nodes[${nodeIndex}].parameters.formFields.values[${valueIndex}].fieldOptions.values`;
   })()
}}",
              "type": "array",
              "value": "={{ $('Write JSON').item.json.nodes[0].parameters.formFields.values[0].fieldOptions.values }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "07635565-f8ea-4fac-b93c-069fbe065ce8",
      "name": "Get all values",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -240,
        -180
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1F73a7uuzLAq916w2JFndumv0JhnCAvOTN-Cn_OOP3uA/edit#gid=0",
          "cachedResultName": "Blad1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1F73a7uuzLAq916w2JFndumv0JhnCAvOTN-Cn_OOP3uA",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1F73a7uuzLAq916w2JFndumv0JhnCAvOTN-Cn_OOP3uA/edit?usp=drivesdk",
          "cachedResultName": "obsidian-n8n"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "3Pu0wlfxgNYzVqY6",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "9ce7bf73-211a-4f5b-b39d-81a2d513a3ef",
      "name": "Format to 'values'",
      "type": "n8n-nodes-base.set",
      "position": [
        20,
        -180
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "e18aa12e-f277-4257-ba27-9262cc7b866a",
              "name": "value",
              "type": "string",
              "value": "={{ $json.title }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d69a3011-97a6-44e9-9b7e-c8e9a248964a",
  "connections": {
    "Write JSON": {
      "main": [
        [
          {
            "node": "n8n | get wf",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "n8n | get wf": {
      "main": [
        [
          {
            "node": "Replace values",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get all values": {
      "main": [
        [
          {
            "node": "Format to 'values'",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Replace values": {
      "main": [
        [
          {
            "node": "n8n | update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format to 'values'": {
      "main": [
        [
          {
            "node": "Write JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "Execute Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets Trigger": {
      "main": [
        [
          {
            "node": "Get all values",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • N8N
  • Formtrigger
  • Googlesheetstrigger
  • Executeworkflow
  • Stickynote

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作